package com.tracy.swagger.controller;

import com.tracy.swagger.bo.UserBo;
import com.tracy.swagger.entity.User;
import com.tracy.swagger.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/swagger")
@Api(tags ="swagger测试类")
public class SwaggerController {


    @GetMapping(value = "/getUser")
    @ApiOperation(value = "获取用户信息",notes = "根据用户id获取用户信息")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,paramType = "query",dataType = "string")
    public Result<User> getUser(@RequestParam("id")Long id){
        User user = new User(1L,"swagger",18,false,new Date());
        Result<User> result = new Result<>(Result.SUCCESS_STATUS,"SUCCESS",user);
        return result;
    }

    @PostMapping(value = "/addUser")
    @ApiOperation(value = "新增用户",notes = "新增用户")
    public Result<User> addUser(@RequestBody UserBo userBo){
        User user = new User(1L,"swagger",18,false,new Date());
        Result<User> result = new Result<>(Result.SUCCESS_STATUS,"SUCCESS",user);
        return result;
    }

    @PostMapping(value = "/updateUser")
    @ApiOperation(value = "更新用户",notes = "更新用户")
    public Result<User> updateUser(@RequestBody UserBo userBo){
        User user = new User(1L,"swagger",18,false,new Date());
        Result<User> result = new Result<>(Result.SUCCESS_STATUS,"SUCCESS",user);
        return result;
    }

    @DeleteMapping(value = "/deleteUser")
    @ApiOperation(value = "删除用户",notes = "根据用户id删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",required = true,paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "authority",value = "用户权限",required = true,paramType = "header",dataType = "string")
    })
    public Result<Boolean> deleteUser(@RequestParam("id")Long id){
        Result<Boolean> result = new Result<>(Result.SUCCESS_STATUS,"SUCCESS",true);
        return result;
    }

}
